package com.example.liuke.guangguang.ui;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.liuke.guangguang.R;
import com.example.liuke.guangguang.adapter.MyBookAdapter;
import com.example.liuke.guangguang.base.baseactivity;
import com.example.liuke.guangguang.bean.bookbean;
import com.example.liuke.guangguang.bean.mseeagebean;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class BookActivity extends baseactivity {

    @BindView(R.id.mynookrecy)
    RecyclerView mynookrecy;
    private RecyclerView recyclerView;
    private List<bookbean> urllist;
    private MyBookAdapter adapter;
    private GridLayoutManager gridLayoutManager;
    int lengh;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        urllist = new ArrayList<>();
        urllist.clear();
        bookbean bookbean = new bookbean();
        bookbean.setVisible(View.VISIBLE);
        bookbean.setUrl("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
        urllist.add(bookbean);
       /* urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");
        urllist.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=973e5976f7f2b211fb2e834efa806511/bd315c6034a85edf0ab7c12645540923dd5475ff.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");
        urllist.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=973e5976f7f2b211fb2e834efa806511/bd315c6034a85edf0ab7c12645540923dd5475ff.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");
        urllist.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=973e5976f7f2b211fb2e834efa806511/bd315c6034a85edf0ab7c12645540923dd5475ff.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");
        urllist.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=973e5976f7f2b211fb2e834efa806511/bd315c6034a85edf0ab7c12645540923dd5475ff.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");*/
        System.out.println("quyu:" + 1 % 5 + 5 % 5 + 9 % 5+ urllist.size() % 5+(5 - urllist.size() % 5 + 5));
        if (urllist.size() % 5 != 0) {
            lengh = ( 10 - urllist.size() % 5 );
            for (int i = 0; i <lengh; i++) {
                bookbean bookbean1 = new bookbean();
                urllist.add(bookbean1);
                System.out.println("quyui:" +i);
            }
        }
        gridLayoutManager = new GridLayoutManager(this, 5);
        //gridLayoutManager.setOrientation(GridLayoutManager.HORIZONTAL);
        adapter = new MyBookAdapter(this, R.layout.bookitem, urllist,lengh);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(BookActivity.this, "onItemClick" + position, Toast.LENGTH_SHORT).show();
            }
        });
        mynookrecy.setLayoutManager(gridLayoutManager);
        mynookrecy.setItemAnimator(new DefaultItemAnimator());
        mynookrecy.setAdapter(adapter);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(mseeagebean mseeagebean) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_book;
    }
}
